package inits

import (
	"context"
	"exam/config"
	"exam/global"
	"fmt"
	"github.com/go-redis/redis/v8"
	"log"
)

func RedisInit() {
	global.Rdb = redis.NewClient(&redis.Options{
		Addr:     config.Config.RedisConfig.Addr, // use default Addr
		Password: config.Config.RedisConfig.Pass, // no password set
		DB:       config.Config.RedisConfig.DB,   // use default DB
	})

	pong, err := global.Rdb.Ping(context.Background()).Result()
	fmt.Println(pong, err)
	if err != nil {
		panic(err)
	} else {
		log.Println("redis init success")
	}
	// Output: PONG <nil>
}
